﻿<cfscript>
    view = createObject("component", "#session.rootDir#.views.layout");
    view.init("Dynamic Group Management", 
        "/jquery/ui-1.8.10/jquery-ui.min.js, /#session.rootDir#/static/js/search.js", 
        "/jquery/ui-1.8.10/themes/cupertino/jquery-ui-1.8.10.custom.css",main,0,0,'sideBarLeft',sideBar);
    view.html();
</cfscript>


<cffunction name="sideBar" access="public" output="true" returntype="any">

    <div id="sideBarLeft">
        <h2>Options</h2>
        <div id="sideBarLinks">
            <a href="##">Edit User</a>
        </div>
    </div>
    
</cffunction>


<cffunction name="main" access="public" output="true" returntype="any">
    <cfparam default="none" name="url.ADUser" />
    <style>
        ul.ui-autocomplete{text-align:left;}
        ##userattrs td{vertical-align:top;}
    </style>
    <cfscript>
        import models.*;
        User = createObject("component", "#session.rootDir#.objects.Users").init();
        User.setADUser(url.ADUser);
        AjaxController = '/#session.rootDir#/controller/AjaxHandler.cfm';
        ViewUser = "/#session.rootDir#/users/viewuser.cfm?ADUser=";
        ViewGroup = "/#session.rootDir#/groups/viewgroup.cfm?ADGroup=";
        ManagerAttrs = User.getADUserManager();
    </cfscript>

    <cfform name="myfrm">
        <cfinput type="hidden" value="#ViewUser#" name="ViewUser"/ >
        <cfinput type="hidden" value="#ViewGroup#" name="ViewGroup" / >
        <cfinput type="hidden" value="#AjaxController#" name="AjaxController" />
        <cfinput type="hidden" value="#User.UserAttrs.UserDN#" name="UserDN" />
        
        <div>
            <cfinput type="text" value="Search for user" name="UserSearch" size="30" />
            <img src="/#SESSION.RootDir#/images/progress.gif" width="16px" height="16px" id="UserProgress" style="display:none;" align="absmiddle"/>
        </div>
        
        <h2><strong>#User.UserAttrs.displayName#</strong></h2>
        <div>
            <cftry>
                <cfimage action="info" source="#User.UserAttrs.Badge#" structname="BadgePic">
                <cfif BadgePic.height GT 200 OR BadgePic.width GT 200>
                    <img src="#BadgePic.source#" width="#(BadgePic.width * (200 / BadgePic.height))#" height="200" />
                <cfelse>
                    <img src="#BadgePic.source#" width="#BadgePic.width#" height="#BadgePic.height#" />
                </cfif>
            <cfcatch type="Any" >
                <cfmail to="bfrick@scf.cc" from="DyGraMan@scf.cc" subject="DyGraMan Error"><cfdump var="#CFCATCH.Detail#"/></cfmail>
            </cfcatch>
            </cftry>
        </div>
        <table id="userattrs" class="dataTable" width="100%">
            <tbody>                
                <tr>
                    <td><strong>Account</strong></td>
                    <td><a href="#ViewUser##trim(User.UserAttrs.sAMAccountName)#">#User.UserAttrs.sAMAccountName#</a></td>
                </tr>           
                <tr>
                    <td><strong>Full Name</strong></td>
                    <td>#User.UserAttrs.displayName#</td>
                </tr>
                <tr>
                    <td><strong>First Name</strong></td>
                    <td>#User.UserAttrs.givenName#</td>
                </tr>
                <tr>
                    <td><strong>Middle Name</strong></td>
                    <td>#User.UserAttrs.initials#</td>
                </tr>
                <tr>
                    <td><strong>Last Name</strong></td>
                    <td>#User.UserAttrs.sn#</td>
                </tr>
                <tr>
                    <td><strong>Title</strong></td>
                    <td>#User.UserAttrs.title#</td>
                </tr>
                <tr>
                    <td><strong>Department</strong></td>
                    <td>#User.UserAttrs.department#</td>
                </tr>
                <tr>
                    <td><strong>Email</strong></td>
                    <td><a href="mailto:#trim(User.UserAttrs.userPrincipalName)#">#User.UserAttrs.userPrincipalName#</a></td>
                </tr>
                <tr>
                    <td>
                        <strong>Manager</strong><br /><br />
                    </td>
                    <td>                        
                        Login: <a href="#ViewUser##trim(ManagerAttrs.sAMAccountName)#">#ManagerAttrs.sAMAccountName#</a><br />
                        Name: #ManagerAttrs.displayName#<br />
                        Title: #ManagerAttrs.title#<br />
                        Department: #ManagerAttrs.department#<br />
                        Email: <a href="mailto:#trim(ManagerAttrs.userPrincipalName)#">#ManagerAttrs.userPrincipalName#</a>
                    </td>
                </tr>
                <tr>
                    <td><strong>Last Logged On</strong></td>
                    <td>#User.SCFPS.usePowerShell("Get-Date -format 'MM/dd/yy hh:mm tt' #User.UserAttrs.lastLogon#")#</td>
                </tr>
                 <tr>
                    <td><strong>Logon Count</strong></td>
                    <td>#User.UserAttrs.logonCount#</td>
                </tr>
                <tr>
                    <td>
                        <strong>Direct Reports</strong><br /><br />
                    </td>
                    <td>
                        <ul>
                        <cfset DirectReports = User.parseUserDNString(User.UserAttrs.directReports) />
                        <cfloop from="1" to="#ArrayLen(DirectReports)#" index="i">
                            <cfset DirectReport = User.SCFAD.getAccountNameByDN(DirectReports[i]) />
                            <li><a href="#ViewUser##trim(DirectReport)#">#DirectReport#</a></li>
                        </cfloop>
                        </ul>
                    </td>
                </tr>
                <tr>
                    <td><strong>My Groups</strong></td>
                    <td>
                        <ul>
                        <cfset Groups = User.getUserOwnedGroups(trim(User.UserAttrs.UserDN)) />
                        <cfloop query="Groups">
                            <li><a href="#ViewGroup##trim(sAMAccountName)#">#sAMAccountName#</a></li>
                        </cfloop>
                        </ul>
                    </td>
                </tr>
                <tr>
                    <td><strong>Member of</strong></td>
                    <td>
                        <ul>
                        <cfset Groups = User.parseGroupDNString(User.UserAttrs.memberOf) />
                        <cfloop from="1" to="#ArrayLen(Groups)#" index="i">
                            <cfset Group = User.SCFAD.getGroupNameByDN(Groups[i]) />
                            <li><a href="#ViewGroup##trim(Group)#">#Group#</a></li>
                        </cfloop>
                        </ul>
                    </td>
                </tr>                
            </tbody>
        </table>
    </cfform>
</cffunction>